package com.ultra.common.dialog;

import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnKeyListener;
import android.view.KeyEvent;

/** 
 * @ClassName: WaitDialog 
 * @Description: 加载进度动画
 * @author jiangshidi QQ:82421098 
 * @date 2013-4-14 上午11:37:08 
 *  
 */
public class WaitDialog  implements OnKeyListener {
	private ProgressDialog dialog;
	
	/** 
	 * @Description: 实例化dialog
	 * @param @param context
	 * @param @param title
	 * @param @param message   设定文件 
	 * @throws 
	 */
	public WaitDialog(Context context,String title ,String message) {
		dialog = ProgressDialog.show(context, title, message);
		dialog.setOnKeyListener(this);
	}
	
	/**
	 * Title: onKey
	 * Description: 监听页面按钮
	 * @param dialog
	 * @param keyCode
	 * @param event
	 * @return 
	 * @see android.content.DialogInterface.OnKeyListener#onKey(android.content.DialogInterface, int, android.view.KeyEvent) 
	 */
	@Override
	public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
		// 如果是返回按键,移除dialog
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			dialog.dismiss();
		}
		return false;
	}

	/** 
	 * @Title: getDialog 
	 * @Description: 返回dialog对象
	 * @param @return    设定文件 
	 * @return ProgressDialog    返回类型 
	 * @throws 
	 */
	public ProgressDialog getDialog() {
		return dialog;
	}
}
